//
//  UITextField+Factory.m
//  即时通讯
//
//  Created by huangtao on 16/7/9.
//  Copyright © 2016年 fish. All rights reserved.
//

#import "UITextField+Factory.h"

@implementation UITextField (Factory)

+ (UITextField *)textFieldWithFrame:(CGRect)frame
                           delegate:(id<UITextFieldDelegate>)delegate
                        placeholder:(NSString *)placeholder
                      returnKeyType:(UIReturnKeyType)returnKeyType
                    backgroundImage:(NSString *)imageName
                    clearButtonMode:(UITextFieldViewMode)clearButtonMode
{
    UITextField *textField = [[UITextField alloc]initWithFrame:frame];
    textField.placeholder = placeholder;
    textField.background = [UIImage imageNamed:imageName];
    textField.delegate = delegate;
    textField.returnKeyType = returnKeyType;
    textField.clearButtonMode = clearButtonMode;
    textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    return textField;
}
// placeholder position
- (CGRect)textRectForBounds:(CGRect)bounds {
    return CGRectInset(bounds, TextFieldHorizontalPadding, TextFieldVerticalPadding);
}

// text position
- (CGRect)editingRectForBounds:(CGRect)bounds {
    return CGRectInset(bounds, TextFieldHorizontalPadding, TextFieldVerticalPadding);
}
- (void)addBackGroundCorRadius
{
    self.background = nil;
    self.backgroundColor = [UIColor whiteColor];
    self.layer.cornerRadius = 5;
    self.layer.masksToBounds = YES;
    self.layer.borderColor = [[UIColor lightGrayColor]CGColor];
    self.layer.borderWidth = 1;
    [self.superview layoutIfNeeded];
}
@end
